package com.shinewind.home.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shinewind.common.constant.messageConstant;
import com.shinewind.home.mapper.IStatusMapper;
import com.shinewind.home.service.IStatusService;
import com.shinewind.pojo.entity.Status;
import com.shinewind.pojo.result.Result;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.ArrayList;
import java.util.List;

@Service
@DubboService
public class StatusServiceImpl extends ServiceImpl<IStatusMapper, Status> implements IStatusService {
    public List<String> getStatusInfoById(@PathVariable("mId") String mId){
        List<Status> StatusList = this.lambdaQuery().eq(Status::getMId, mId).orderByDesc(Status::getSaleTime).list();
        List<String> saleTimeList = new ArrayList<>();
        for (Status status : StatusList) {
            if (StatusList.size() >= 1 && !StrUtil.isEmpty(status.getSaleTime().toString())) {
                StringBuilder dateStr = new StringBuilder(DateUtil.format(status.getSaleTime(), "yyyy年MM月"));
                if(dateStr.charAt(5) == '0'){
                    dateStr.deleteCharAt(5);
                }
                saleTimeList.add(dateStr.toString()+status.getStatus());
            }
        }
        return saleTimeList;
    }
}
